package com.ruoyi.web.controller.system;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CamsEnrollInfo;
import com.ruoyi.system.service.ICamsEnrollInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报名信息Controller
 *
 * @author anskory
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/system/info")
public class CamsEnrollInfoController extends BaseController {
    @Autowired
    private ICamsEnrollInfoService camsEnrollInfoService;

/**
 * 查询报名信息列表
 */
@PreAuthorize("@ss.hasPermi('system:info:list')")
@GetMapping("/list")
    public TableDataInfo list(CamsEnrollInfo camsEnrollInfo) {
        startPage();
        List<CamsEnrollInfo> list = camsEnrollInfoService.selectCamsEnrollInfoList(camsEnrollInfo);
        return getDataTable(list);
    }

    /**
     * 导出报名信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "报名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CamsEnrollInfo camsEnrollInfo) {
        List<CamsEnrollInfo> list = camsEnrollInfoService.selectCamsEnrollInfoList(camsEnrollInfo);
        ExcelUtil<CamsEnrollInfo> util = new ExcelUtil<CamsEnrollInfo>(CamsEnrollInfo. class);
        util.exportExcel(response, list, "报名信息数据");
    }

    /**
     * 获取报名信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(camsEnrollInfoService.getById(id));
    }

    /**
     * 新增报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "报名信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CamsEnrollInfo camsEnrollInfo) {
        return toAjax(camsEnrollInfoService.save(camsEnrollInfo));
    }

    /**
     * 修改报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "报名信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CamsEnrollInfo camsEnrollInfo) {
        return toAjax(camsEnrollInfoService.updateById(camsEnrollInfo));
    }

    /**
     * 删除报名信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "报名信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(camsEnrollInfoService.removeByIds(Arrays.asList(ids)));
    }
}
